home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Sound / Amster / Source / mui.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-31  |  4.5 KB  |  224 lines

  1. /*
  2. ** MUI Helper Functions of MadCat!
  3. **
  4. ** This program is free software; you can redistribute it and/or modify
  5. ** it under the terms of the GNU General Public License as published by
  6. ** the Free Software Foundation; either version 2 of the License, or
  7. ** (at your option) any later version.
  8. **
  9. ** This program is distributed in the hope that it will be useful,
  10. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ** GNU General Public License for more details.
  13. **
  14. ** You should have received a copy of the GNU General Public License
  15. ** along with this program; if not, write to the Free Software
  16. ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17. */
  18.  
  19. #include <proto/locale.h>
  20.  
  21. #include <libraries/gadtools.h>
  22.  
  23. #include "include/mui.h"
  24.  
  25. struct Locale *locale = NULL;
  26.  
  27.  
  28. #ifdef __PPC__
  29. /* for some reason inline version of this function doesn't work well */
  30. /* so this is the vararg stub for MUI_NewObjectA */
  31. Object *MUI_NewObject(char *classname, Tag tag1,...)
  32. {
  33.     ULONG mav[50];
  34.     va_list tags;
  35.     int i=0;
  36.  
  37.     mav[i] = tag1;
  38.     if(mav[i] != TAG_DONE)
  39.     {
  40.         va_start(tags, tag1);
  41.         mav[++i] = va_arg(tags, ULONG);
  42.         i++;
  43.         while(i<50)
  44.         {
  45.             mav[i] = va_arg(tags, ULONG);
  46.             if(mav[i] == TAG_DONE) break;
  47.             mav[++i] = va_arg(tags, ULONG);
  48.             i++;
  49.         }
  50.         va_end(tags);
  51.     }
  52.     return(MUI_NewObjectA(classname, (struct TagItem *)&mav));
  53. }
  54.  
  55. /* ppc passes varargs on both registers and stack, so this is necessary */
  56. ULONG DoSuperNew(struct IClass *cl, Object *obj, ...)
  57. {
  58.     ULONG mav[50];
  59.     ULONG ret;
  60.     va_list tags;
  61.     struct opSet myopSet;
  62.     int i=0;
  63.  
  64.     va_start(tags, obj);
  65.     while(i<50)
  66.     {
  67.         mav[i] = va_arg(tags, ULONG);
  68.         if(mav[i] == TAG_DONE) break;
  69.         mav[i+1] = va_arg(tags, ULONG);
  70.         if(mav[i] == TAG_MORE) break;
  71.         i += 2;
  72.     }
  73.     va_end(tags);
  74.  
  75.     myopSet.MethodID = OM_NEW;
  76.     myopSet.ops_AttrList = (struct TagItem *) &mav;
  77.     myopSet.ops_GInfo = NULL;
  78.     ret = DoSuperMethodA(cl, obj, (APTR)&myopSet);
  79.  
  80.     return ret;
  81. }
  82. #else
  83. ULONG __stdargs DoSuperNew(struct IClass *cl,Object *obj,ULONG tag1,...)
  84. {
  85.     return(DoSuperMethod(cl,obj,OM_NEW,&tag1,NULL));
  86. }
  87. #endif
  88.  
  89.  
  90. Object *maketmenu(const UBYTE *msg)
  91. {
  92.     char *title = (char *)msg;
  93.  
  94.     if(title[1]==0)
  95.         return(MenuitemObject,
  96.                MUIA_Menuitem_Title, title+2,
  97.                MUIA_Menuitem_Shortcut, title,
  98.                MUIA_Menuitem_Toggle, TRUE,
  99.                MUIA_Menuitem_Checkit, TRUE,
  100.                End);
  101.     else
  102.         return(MenuitemObject,
  103.                MUIA_Menuitem_Title, title,
  104.                MUIA_Menuitem_Toggle, TRUE,
  105.                MUIA_Menuitem_Checkit, TRUE,
  106.                End);
  107. }
  108.  
  109.  
  110. Object *makemenu(const UBYTE *msg)
  111. {
  112.     char *title = (char *)msg;
  113.  
  114.     if(msg==NULL) return(MenuitemObject,MUIA_Menuitem_Title,NM_BARLABEL,End);
  115.  
  116.     if(title[1]==0)
  117.         return(MenuitemObject,
  118.                MUIA_Menuitem_Title, title+2,
  119.                MUIA_Menuitem_Shortcut, title,
  120.                End);
  121.     else
  122.         return(MenuitemObject,MUIA_Menuitem_Title,title,End);
  123. }
  124.  
  125.  
  126. Object *maketoggle(const UBYTE *msg, Object **tog)
  127. {
  128.     Object *obj,*obj2;
  129.  
  130.     obj = HGroup,
  131.         Child, obj2 = ImageObject,
  132.             ButtonFrame,
  133.             MUIA_Background, MUII_ButtonBack,
  134.             MUIA_InputMode, MUIV_InputMode_Toggle,
  135.             MUIA_ShowSelState, FALSE,
  136.             MUIA_CycleChain, 1,
  137.             MUIA_Image_Spec, "6:15",
  138.         End,
  139.         Child, TextObject,
  140.             MUIA_Text_Contents, (char *)msg,
  141.         End,
  142.     End;
  143.  
  144.     if(obj) {
  145.         *tog = obj2;
  146.         return(obj);
  147.     } else
  148.         return(NULL);
  149. }
  150.  
  151.  
  152. int mui_classes_setup(muiclass mcl[])
  153. {
  154.     int i=0;
  155.     struct MUI_CustomClass *tmp;
  156.  
  157.     while(mcl[i].supername)
  158.     {
  159.         tmp = MUI_CreateCustomClass(NULL, mcl[i].supername, NULL, mcl[i].datasize, mcl[i].dispatcher);
  160.         if(!tmp) return 0;
  161.         *mcl[i].ptr = tmp;
  162.         i++;
  163.     }
  164.     return 1;
  165. }
  166.  
  167.  
  168. void mui_classes_cleanup(muiclass mcl[])
  169. {
  170.     int i=0;
  171.  
  172.     while(mcl[i].supername)
  173.     {
  174.         if(*mcl[i].ptr) MUI_DeleteCustomClass(*mcl[i].ptr);
  175.         i++;
  176.     }
  177. }
  178.  
  179.  
  180. void SPrintF(char *outstr, char *fmtstr, ...)
  181. {
  182.     struct Hook hook;
  183. #ifdef __PPC__
  184.     va_list ap;
  185.     ULONG arg[32];
  186.     int args = 0, i;
  187.  
  188.     for (i=0; fmtstr[i] != '\0'; i++) {
  189.         if (fmtstr[i] == '%' && fmtstr[i+1] != '%') args++;
  190.     }
  191.  
  192.     va_start(ap, fmtstr);
  193.     for (i=0; i<args; i++) {
  194.         arg[i] = va_arg(ap, ULONG);
  195.     }
  196.     va_end(ap);
  197. #endif
  198.  
  199.     InitHook(&hook, putChar, outstr);
  200.  
  201. #ifdef __PPC__
  202.     FormatString(locale, fmtstr, &arg[0], &hook);
  203. #else
  204.     FormatString(locale, fmtstr, &fmtstr+1, &hook);
  205. #endif
  206. }
  207.  
  208.  
  209. #ifdef __MORPHOS__
  210. static void putChar_gate(void)
  211. {
  212.     struct Hook *hook = (struct Hook *)REG_A0;
  213.     char c = (char)REG_A1;
  214. #else
  215. void SAVEDS ASM putChar(REG(a0, struct Hook *hook), REG(a1, char c), REG(a2, struct Locale *locale))
  216. {
  217. #endif
  218.     char **tmp;
  219.  
  220.     ((char *)hook->h_Data)[0] = c;
  221.     tmp = (char **)(&hook->h_Data);
  222.     (*tmp)++;
  223. }
  224.